package com.epoint.mobileoa.ui.deptchoose;

import java.util.ArrayList;
import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.db.DBHelp;
import com.epoint.mobileoa.model.Ou;

/**
 * @author liyc
 * @time 2012-5-7 下午2:51:54
 * @annotation 
 */
public class DeptChooseSimpleView extends SuperView {

	private List<Ou> list = new ArrayList<Ou>();
	private ListView lvDept;
	public static Ou selectedUO;
	@Override
	public void initControls() {
		list = DBHelp.getAllOuList(this);
		lvDept = (ListView) findViewById(R.id.lvDept);
		lvDept.setOnItemClickListener(this);
		MyAdapter adapter = new MyAdapter();
		lvDept.setAdapter(adapter);
		
	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		selectedUO = list.get(position);
		finish();
	}

	@Override
	public void refresh(Object... param) {
	}

	@Override
	public int getLayoutInt() {
		return R.layout.deptchoosesimpleview;
	}

	@Override
	public String setTitle() {
		return "部门选择";
	}
	
	class MyAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int position) {
			return null;
		}

		@Override
		public long getItemId(int position) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				LayoutInflater mInflater = LayoutInflater.from(DeptChooseSimpleView.this);
				convertView = mInflater.inflate(R.layout.epointxmlist, null);
				holder.ml_mailimg = (ImageView) convertView
						.findViewById(R.id.ml_mailimg);
				holder.ml_attach = (ImageView) convertView
						.findViewById(R.id.ml_attach);
				holder.ml_mailtitle = (TextView) convertView
						.findViewById(R.id.ml_mailtitle);
				holder.ml_sandt = (TextView) convertView
						.findViewById(R.id.ml_sandt);

				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			holder.ml_mailimg.setVisibility(View.GONE);
			holder.ml_mailtitle.setText(list.get(position).ouname);
			holder.ml_sandt.setVisibility(View.GONE);
			return convertView;
		}
		
	}
	
	public class ViewHolder {
		public ImageView ml_mailimg;
		public ImageView ml_attach;
		public TextView ml_mailtitle;
		public TextView ml_sandt;
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param) {
	}

	
}
